<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('上传培训材料')"/>
    <th:block th:include="include :: select2-css"/>
</head>

<body>
<div class="ui-layout-center">
    <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="user-form">
                    <input name="id" id="id" type="hidden" th:value="${id}"/>
                    <div class="select-list">
                        <ul>
                            <li>
                                <input id="filePath" name="filePath" class="form-control" type="file" required>
                            </li>
                            <li>
                                附件类型：
                                <select name="fileType" id="fileType">
                                    <option value="">请选择</option>
                                    <option value="培训现场照片">培训现场照片</option>
                                    <option value="培训签到表">培训签到表</option>
                                </select>
                            </li>
                            <li>

                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">

            </div>

            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
</div>

<th:block th:include="include :: footer"/>
<th:block th:include="include :: layout-latest-js"/>
<th:block th:include="include :: ztree-js"/>

<script th:inline="javascript">
    var prefix = ctx + "trainManage";
    $(function () {
        var panehHidden = false;
        if ($(this).width() < 800) {
            panehHidden = true;
        }
        $('body').layout({initClosed: panehHidden, west__size: 350});
        queryData();
    });

    function queryData() {
        var trainId = $("#id").val();
        var columns = [];
        var checkbox = {checkbox: true};
        var id = {field: 'id', title: '序号'};
        var image = {
            title: '点击放大查看图片',
            align: "center",
            formatter: function (value, row, index) {
                return $.table.imageView(ctx + row.fileName,800,1200);
            }
        };

        var fileType = {field: 'fileType', title: '附件类型'};

        var uploadTime = {field: 'uploadTime', title: '上传时间'};

        columns.push(checkbox, id, image,fileType, uploadTime);

        var options = {
            code: "id",
            uniqueId: "id",
            url: prefix + "/findFileDataList?trainId=" + trainId,
            removeUrl: prefix + "/removeFile",
            escape: true,
            showPageGo: true,
            rememberSelected: true,
            height: $(window).height() - 120,
            sortOrder: "desc",
            modalName: "上传培训材料",
            columns: columns
        };
        $.table.init(options);
    }

    function upload(){
        var trainId = $("#id").val();
        var fileType = $("#fileType").val();
        var formData = new FormData();
        if ($('#filePath')[0].files[0] == null) {
            $.modal.alertWarning("请先选择文件路径");
            return false;
        }
        formData.append('trainId', trainId);
        formData.append('file', $('#filePath')[0].files[0]);
        formData.append('fileType', fileType);

        $.ajax({
            url: prefix + "/upload",
            type: 'post',
            cache: false,
            data: formData,
            processData: false,
            contentType: false,
            dataType: "json",
            success: function (result) {
                $.table.search();
            }
        });
    }

</script>
</body>
</html>
